//
//  LJM_SONG_Sub_ViewController.m
//  wind
//
//  Created by 李金明 on 16/1/18.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJM_SONG_Sub_ViewController.h"
#import "LJM_SONG_Sub_CollectionViewCell.h"
#import "LJM_FM_CollectionReusableView.h"
//collectionfowl的坐标
#define COLLECTIONFOWLEDGE 5//边界
#define COLLECTWIDTH 20
#define COLLECTHEADHEIGHT 20//区头的高度
#define COLLECTHEIGHT 40//CELL的高度
@interface LJM_SONG_Sub_ViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UIButton *bactButton;
@property (nonatomic, retain) UIView *barview;
@property (nonatomic, retain) UILabel *titleLab;
@property (nonatomic, retain) UICollectionView *collectionV;
@property (nonatomic, retain) NSMutableArray *sceneArr;//场景的数组
@property (nonatomic, retain) NSMutableArray *MoodArr;//心情的数组
@property (nonatomic, retain) NSMutableArray *styleArr;//风格的数组
@property (nonatomic, retain) NSMutableArray *themeArr;//主题的数组
@property (nonatomic, retain) NSMutableArray *languageArr;//语种的数组
@end

@implementation LJM_SONG_Sub_ViewController
- (void)dealloc
{
    self.backDelegate = nil;
    [_sceneArr release];
    [_MoodArr release];
    [_styleArr release];
    [_themeArr release];
    [_languageArr release];
    [_collectionV release];
    [_bactButton release];
    [_barview release];
    [_titleLab release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //添加navigationBar
    [self addNavigationBar];
    //数组填充
    [self cellArr];
    //添加collectionView
    [self addCollectionView];
}
#pragma 数组填充
- (void)cellArr
{
    self.sceneArr = [NSMutableArray arrayWithObjects:@"酒吧", @"校园", @"夜晚", @"黄昏", @"工作", @"下午茶", @"清晨", @"休闲", @"学习", @"聚会", @"KTV", @"散步", @"在路上", @"旅行", @"缠绵", @"运动", @"洗澡", @"开车", @"约会", @"睡前", @"做家务", nil];
    self.MoodArr = [NSMutableArray arrayWithObjects:@"温暖", @"悲伤", @"思念", @"孤独", @"浪漫", @"安静", @"放松", @"励志", @"伤感", @"聚会", @"宣泄", @"治愈", @"感动", @"欢快", @"快乐", @"00后", nil];
    self.styleArr = [NSMutableArray arrayWithObjects:@"原声", @"古典", @"独立", @"蓝调", @"说唱", @"摇滚", @"乡村", @"新世纪", @"世界音乐", @"轻音乐", @"民谣", @"流行", @"拉丁", @"爵士", @"金属", @"R&B", @"电子", @"另类", @"中国风", @"古风", @"朋克", nil];
    self.themeArr = [NSMutableArray arrayWithObjects:@"翻唱", @"游戏", @"胎教", @"网络歌曲", @"动漫", @"经典", @"80后", @"影视", @"90后", @"童谣", @"神曲", @"70后", nil];
    self.languageArr = [NSMutableArray arrayWithObjects:@"日语", @"韩语", @"英语", @"华语", @"小语种", nil];

}
#pragma 添加collectionView
- (void)addCollectionView
{
    UICollectionViewFlowLayout *flowLy = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    flowLy.sectionInset = UIEdgeInsetsMake(COLLECTIONFOWLEDGE + COLLECTIONFOWLEDGE, COLLECTIONFOWLEDGE, COLLECTIONFOWLEDGE, COLLECTIONFOWLEDGE);
    flowLy.itemSize = CGSizeMake((self.view.frame.size.width - COLLECTIONFOWLEDGE - COLLECTIONFOWLEDGE - COLLECTIONFOWLEDGE - COLLECTIONFOWLEDGE - COLLECTIONFOWLEDGE) / 4, COLLECTHEIGHT);
    flowLy.minimumLineSpacing = COLLECTIONFOWLEDGE;
    flowLy.minimumInteritemSpacing = COLLECTIONFOWLEDGE;
    flowLy.headerReferenceSize = CGSizeMake(self.view.frame.size.width, COLLECTHEADHEIGHT);
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 100) collectionViewLayout:flowLy];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionV];
    [_collectionV release];
    [self.collectionV registerClass:[LJM_FM_CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
    
    [self.collectionV registerClass:[LJM_SONG_Sub_CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
}
#pragma collectionView的协议方法
#pragma 个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (0 == section) {
        return self.sceneArr.count;
    } else if (1 == section) {
        return self.MoodArr.count;
    } else if (2 == section) {
        return self.styleArr.count;
    } else if (3 == section) {
        return self.themeArr.count;
    } else {
        return self.languageArr.count;
    }

}
#pragma cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
LJM_SONG_Sub_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (0 == indexPath.section) {
        
        cell.titleLab.text = [self.sceneArr objectAtIndex:indexPath.row];
    } else if (1 == indexPath.section) {
cell.titleLab.text = [self.MoodArr objectAtIndex:indexPath.row];
    } else if (2 == indexPath.section) {
cell.titleLab.text = [self.styleArr objectAtIndex:indexPath.row];
    } else if (3 == indexPath.section) {
cell.titleLab.text = [self.themeArr objectAtIndex:indexPath.row];
    } else {
cell.titleLab.text = [self.languageArr objectAtIndex:indexPath.row];
    }
    
    return cell;
}
#pragma 组的个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 5;
}
#pragma 点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //返回按键
    [self barAction];
    if (0 == indexPath.section) {
        
     [self.backChangeDelegate backSongChangeViewStr:[self.sceneArr objectAtIndex:indexPath.row]];
    } else if (1 == indexPath.section) {
        [self.backChangeDelegate backSongChangeViewStr:[self.MoodArr objectAtIndex:indexPath.row]];
    } else if (2 == indexPath.section) {
        [self.backChangeDelegate backSongChangeViewStr:[self.styleArr objectAtIndex:indexPath.row]];
    } else if (3 == indexPath.section) {

        [self.backChangeDelegate backSongChangeViewStr:[self.themeArr objectAtIndex:indexPath.row]];
    } else {

        [self.backChangeDelegate backSongChangeViewStr:[self.languageArr objectAtIndex:indexPath.row]];
    }
    
    
}
#pragma 定义区头
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    LJM_FM_CollectionReusableView *headerView=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
    
    if (0 == indexPath.section) {
         headerView.titleLab.text = @"场景";
    } else if (1 == indexPath.section) {
         headerView.titleLab.text = @"心情";
    } else if (2 == indexPath.section) {
         headerView.titleLab.text = @"风格";
    } else if (3 == indexPath.section) {
         headerView.titleLab.text = @"主题";
    } else {
         headerView.titleLab.text = @"语种";
    }
    
    return headerView;
}
#pragma 添加navigationBar
- (void)addNavigationBar
{
    self.barview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, NAVIGATIONBARHEIGHT)];
    self.barview.userInteractionEnabled = YES;
    self.barview.backgroundColor = [UIColor colorWithRed:69 / 255.0 green:175 / 255.0 blue:248 / 255.0 alpha:1.0];
    [self.navigationController.navigationBar addSubview:self.barview];
    [_barview release];
    self.bactButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bactButton setTitle:@"返回" forState:UIControlStateNormal];
    [self.bactButton addTarget:self action:@selector(barAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bactButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.barview addSubview:self.bactButton];
    [self.bactButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.barview.mas_left).offset(10);
        make.width.mas_equalTo(@50);
        make.bottom.equalTo(self.barview.mas_bottom).offset(-5);
        make.height.mas_equalTo(@30);
    }];
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.text = @"分类";
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.font = [UIFont boldSystemFontOfSize:20];
    self.titleLab.textColor = [UIColor whiteColor];
    [self.barview addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.barview.mas_centerX);
        make.width.mas_equalTo(@50);
        make.centerY.equalTo(self.bactButton.mas_centerY);
        make.height.mas_equalTo(@30);
    }];
    
    
    
    
}
#pragma 返回按钮
- (void)barAction
{
    [self.navigationController popViewControllerAnimated:YES];
    [self.barview removeFromSuperview];
    [self.backDelegate backSongDelegate];

    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
